//
//  CommentViewController.m
//  FootBallTest_huang
//
//  Created by lanou3g on 15/6/1.
//  Copyright (c) 2015年 lanou3g.com. All rights reserved.
//

#import "CommentViewController.h"
#import "CommentTableViewController.h"
#import "NewsaDetailsViewController.h"
//至于如何获取IOS系统版本号通过如下可获取
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
@interface CommentViewController ()

@end

@implementation CommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableVC = [[CommentTableViewController alloc] init];
    
    self.navigationController.navigationBar.translucent = NO;
    _tableVC.newsModle = self.newsModle;
    
    
    [self addChildViewController:self.tableVC];
    [self.view addSubview:self.tableVC.view];
    
    //确定tableVC的宽度
    CGRect frame = self.tableVC.view.frame;
    frame.size.width = CGRectGetWidth(self.view.bounds);
    self.tableVC.view.frame = frame;
    
    
    
    
    
    
    
//    输入框textField
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, self.view.frame.size.height-100, self.view.frame.size.width-20, 30)];
    _textField.placeholder = @"评论";
    _textField.delegate = self;
    //    textField.secureTextEntry = secureTextEntry;
    _textField.textAlignment = NSTextAlignmentLeft;
    _textField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:_textField];
    
    

    
    
    
    
    
    
    
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
    customView.backgroundColor = [UIColor lightGrayColor];
    _textField.inputAccessoryView = customView;
    UILabel * titleLable = [[UILabel alloc] initWithFrame:CGRectMake(150, 10, 70, 20)];
    titleLable.backgroundColor = [UIColor lightGrayColor];
    
    
    UIButton * cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.frame = CGRectMake(10, 10, 40, 20);
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchDown];
    [customView addSubview:cancelButton];
    
    
    UIButton * sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    sureButton.backgroundColor = [UIColor lightGrayColor];
    sureButton.frame = CGRectMake(self.view.frame.size.width-50, 10, 40, 20);
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [sureButton addTarget:self action:@selector(sureButtonAction:) forControlEvents:UIControlEventTouchDown];
    [customView addSubview:sureButton];
    
    
    self.CommentTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 40, self.view.frame.size.width-20, 70)];
    _CommentTextField.backgroundColor = [UIColor whiteColor];
    _CommentTextField.placeholder = @"评论";
    _CommentTextField.delegate = self;
    _CommentTextField.textAlignment = NSTextAlignmentLeft;
    _CommentTextField.borderStyle = UITextBorderStyleRoundedRect;
    [customView addSubview:_CommentTextField];
    _CommentTextField.borderStyle =  UITextBorderStyleNone;
    
    
    titleLable.text = @"我来评论";
    [customView addSubview:titleLable];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeContentViewPoint:) name:UIKeyboardWillShowNotification object:nil];
    
    
    UIBarButtonItem * leftBack = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(leftBackAction:)];
    self.navigationItem.leftBarButtonItem = leftBack;
    leftBack.tintColor = [UIColor whiteColor];
    
}

- (void)leftBackAction:(UIBarButtonItem *)BBI
{
    [self.navigationController popViewControllerAnimated:YES];
}



    // 根据键盘状态，调整_mainView的位置
- (void) changeContentViewPoint:(NSNotification *)notification{
    NSDictionary *userInfo = [notification userInfo];
    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGFloat keyBoardEndY = value.CGRectValue.origin.y;  // 得到键盘弹出后的键盘视图所在y坐标
        
    NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
        
    // 添加移动动画，使视图跟随键盘移动
    [UIView animateWithDuration:duration.doubleValue animations:^{
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationCurve:[curve intValue]];
            
        _mainView.center = CGPointMake(_mainView.center.x, keyBoardEndY - 20 - _mainView.bounds.size.height/2.0);   // keyBoardEndY的坐标包括了状态栏的高度，要减去
            
    }];
}


- (void)rightBIAction:(UIBarButtonItem *)BI
{
//        NSLog(@"分享");
}
- (void)cancelButtonAction:(UIButton *)button
{
    [_textField resignFirstResponder];
    [_CommentTextField resignFirstResponder];
//    NSLog(@"取消");
}
- (void)sureButtonAction:(UIButton *)button
{
//    NSLog(@"确定");
}
    
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    
    [_textField resignFirstResponder];
    [_CommentTextField resignFirstResponder];
    return YES;
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
